.\" -*- nroff -*-
.\" Copyright 2013 Los Alamos National Security, LLC. All rights reserved.
.\" Copyright 2010 Cisco Systems, Inc.  All rights reserved.
.\" Copyright 2006-2008 Sun Microsystems, Inc.
.\" Copyright (c) 1996 Thinking Machines
.\" $COPYRIGHT$
.TH MPI_Type_create_subarray 3 "Jun 10, 2020" "4.0.4" "Open MPI"
.SH NAME
\fBMPI_Type_create_subarray\fP \- Creates a data type describing an \fIn\fP-dimensional subarray of an \fIn\fP-dimensional array.

.SH SYNTAX
.ft R
.SH C Syntax
.nf
#include <mpi.h>
int MPI_Type_create_subarray(int \fIndims\fP, const int \fIarray_of_sizes[]\fP, const int \fIarray_of_subsizes[]\fP, const int \fIarray_of_starts[]\fP, int \fIorder\fP, MPI_Datatype \fIoldtype\fP, MPI_Datatype \fI*newtype\fP)

.fi
.SH INPUT PARAMETERS
.ft R
.TP 1i
ndims
Number of array dimensions (positive integer).
.TP 1i
array_of_sizes
Number of elements of type \fIoldtype\fP in each dimension of the full array (array of positive integers).
.TP 1i
array_of_subsizes
Number of elements of type \fIoldtype\fP in each dimension of the subarray (array of positive integers).
.TP 1i
array_of_starts
Starting coordinates of the subarray in each dimension (array of nonnegative integers).
.TP 1i
order
Array storage order flag (state).
.TP 1i
oldtype
Array element data type (handle).


.SH OUTPUT PARAMETERS
.ft R
.TP 1i
newtype
New data type (handle).
.TP 1i
IERROR
Fortran only: Error status (integer).

.SH DESCRIPTION
.ft R
The subarray type constructor creates an MPI data type describing an \fIn\fP-dimensional subarray of an \fIn\fP-dimensional array. The subarray may be situated anywhere within the full array, and may be of any nonzero size up to the size of the larger array as long as it is confined within this array. This type constructor facilitates creating file types to access arrays distributed in blocks among processes to a single file that contains the global array.
.sp
This type constructor can handle arrays with an arbitrary number of dimensions and works for both C- and Fortran-ordered matrices (that is, row-major or column-major). Note that a C program may use Fortran order and a Fortran program may use C order.
.sp
The \fIndims\fP parameter specifies the number of dimensions in the full data array and gives the number of elements in \fIarray_of_sizes\fP, \fIarray_of_subsizes\fP, and \fIarray_of_starts\fP.
.sp
The number of elements of type \fIoldtype\fP in each dimension of the \fIn\fP-dimensional array and the requested subarray are specified by \fIarray_of_sizes\fP and \fIarray_of_subsizes\fP, respectively. For any dimension \fIi\fP, it is erroneous to specify \fIarray_of_subsizes[i]\fP < 1 or \fIarray_of_subsizes[i]\fP > \fIarray of sizes[i]\fP.
.sp
The \fIarray_of_starts\fP contains the starting coordinates of each dimension of the subarray. Arrays are assumed to be indexed starting from zero. For any dimension \fIi\fP, it is erroneous to specify
.sp
.nf
\fIarray_of_starts[i]\fP < 0
.fi
.sp
or
.sp
.nf
\fIarray_of_starts[i]\fP > (\fIarray_of_sizes[i]\fP - \fIarray_of_subsizes[i]\fP).
.fi
.sp
The \fIorder\fP argument specifies the storage order for the subarray as well as the full array. It must be set to one of the following:
.sp
- MPI_ORDER_C: The ordering used by C arrays, (that is, row-major order)
.sp
- MPI_ORDER_FORTRAN: The ordering used by Fortran arrays, (that is, column-major order)
.sp
A \fIndims\fP-dimensional subarray (\fInewtype\fP) with no extra padding can be defined by the function Subarray() as follows:
.sp
.nf
   newtype = Subarray(ndims, {size , size ,\..., size       },
                                  0      1           ndims-1
             {subsize , subsize , \..., subsize       },
                     0         1               ndims-1
             {start , start , \..., start       }, \fIoldtype\fP)
                   0       1             ndims-1
.fi
.sp
Let the typemap of \fIoldtype\fP have the form:
.sp
.nf
   {(type , disp ), (type , disp ), \..., (type   , disp   )}
         0      0        1      1              n-1      n-1
.fi
.sp
where type\fIi\fP is a predefined MPI data type, and let \fIex\fP be the extent of \fIoldtype\fP.
.sp
The Subarray() function is defined recursively in three equations on page 72 of the MPI-2 standard.
.sp
For an example use of MPI_Type_create_subarray in the context of I/O, see Section 9.9.2 of the MPI-2 standard.


.SH NOTES
.ft R
In a Fortran program with arrays indexed starting from 1, if the starting coordinate of a particular dimension of the subarray is \fIn\fP, then the entry in array of starts for that dimension is \fIn\fP-1.

.SH ERRORS
Almost all MPI routines return an error value; C routines as the value of the function and Fortran routines in the last argument. C++ functions do not return errors. If the default error handler is set to MPI::ERRORS_THROW_EXCEPTIONS, then on error the C++ exception mechanism will be used to throw an MPI::Exception object.
.sp
Before the error value is returned, the current MPI error handler is
called. By default, this error handler aborts the MPI job, except for I/O function errors. The error handler may be changed with MPI_Comm_set_errhandler; the predefined error handler MPI_ERRORS_RETURN may be used to cause error values to be returned. Note that MPI does not guarantee that an MPI program can continue past an error.


